import { validateip } from '@/util/validate'
import { rule } from "@/util/validateRules";
export default {
  data(){
    //验证ip地址
    const validateIp = (rule, value, callback) => {
      if (validateip(value)[0]) {
        callback(new Error(validateip(value)[1]))
      } else {
        callback()
      }
    }
    const portRule = (rule, value, callback) => {
      if (value > 65535){
        callback(new Error('最大值不得超过65535'))
      } else {
        callback()
      }
    }
    return {
      //接入接出类型
      commList:[
        {
          label: '接入',
          value: 'IN',
        },
        {
          label: '接出',
          value: 'OUT',
        },
      ],


      baseRules:{
        systemCode: [
          {required: true, message: '请选择项目名称', trigger: 'change'}
        ],

        groupCode: [
          {required: true, message: '请选择服务名称', trigger: 'change'}
        ],
      },

      //表单验证
      rules: {

        charset: [
          {required: true, message: '请选择字符集编码', trigger: 'change'}
        ],

        enable: [
          {required: true, message: '请选择是否启用', trigger: 'change'}
        ],

        connetionType: [
          {required: true, message: '请选择连接类型', trigger: 'change'}
        ],

        ip: [
          {required: true, validator: validateIp,  trigger: 'blur'}
        ],

        port: [
          {required: true, message: '请输入端口号',  trigger: 'blur'},
          {validator: portRule,  trigger: 'blur'}
        ],

        maxSize: [
          {required: true, message: '请输入最大线程数',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        coreSize: [
          {required: true, message: '请输入核心线程数',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        capacity: [
          {required: true, message: '请输入缓冲队列大小',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        aliveTime: [
          {required: true, message: '请输入空闲线程存活时间',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        maxFrameLength: [
          {required: true, message: '请输入报文最大长度',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        lengthFieldOffset: [
          {required: true, message: '请输入长度的数据起始位置',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        lengthFieldLength: [
          {required: true, message: '请输入报文数据长度的字段长度',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        lengthAdjustment: [
          {required: true, message: '请输入内容调整长度',  trigger: 'blur'},
        ],

        initialBytesToStrip: [
          {required: true, message: '请输入跳过字节数',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        len: [
          {required: true, message: '请输入定长报文总长度',  trigger: 'blur'},
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        conTimeout:[
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        receiveTimeout: [
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        msgTimeout: [
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        maxConnections: [
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        maxSessions: [
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        consumers: [
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        ccsid: [
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        msgLength: [
          { validator: rule.validatorNumber, trigger: 'blur'}
        ],

        endChar: [
          {required: true, message: '请输入结束符',  trigger: 'blur'}
        ],

        jmsType: [
          {required: true, message: '请选择实现类型',  trigger: "change"}
        ],

        url: [
          {required: true, message: '请输入连接url',  trigger: 'blur'}
        ],

        receiveDest: [
          {required: true, message: '请输入接收队列',  trigger: 'blur'}
        ],

        receiveQueueName: [
          {required: true, message: '请输入接收队列',  trigger: 'blur'}
        ],

        channel: [
          {required: true, message: '请输入通道名称',  trigger: 'blur'}
        ],

        queueManager: [
          {required: true, message: '请输入队列管理器',  trigger: 'blur'}
        ],

        qcuName: [
          {required: true, message: '请输入队列管理器',  trigger: 'blur'}
        ],

        address: [
          {required: true, message: '请输入服务地址',  trigger: 'blur'}
        ],

        keystore: [
          {required: true, message: '请输入证书文件',  trigger: 'blur'}
        ],

        keypassword: [
          {required: true, message: '请输入证书密码',  trigger: 'blur'}
        ],

        dealclass: [
          {required: true, message: '请输入服务类名',  trigger: 'blur'}
        ],

      },


      _form:{
        /** 基础配置 **/
        charset: '', //字符集编码
        enable: '', //是否启用

        //tcp
        connetionType: '', //连接类型
        ip: '', //ip地址
        port: '', //端口号

        //jms
        jmsType: '', //实现类型
        url: '', //连接url
        persistent: '', //持久化
        sendDest: '', //发送队列
        receiveDest: '', //接收队列
        fileDir: '', //文件目录
        consumers: '', //消费者连接数
        maxSessions: '', //会话数
        //mq
        channel: '', //通道名称
        queueManager: '', //队列管理器
        receiveTimeout: '', //接收超时时间
        msgTimeout: '', //消息周期
        maxConnections: '', //最大连接
        ccsid: '', //ccsid
        //tonLinkQ
        msgType: '', //消息类型
        priority: '', //优先级
        encryptOrComp: '', //传送方式
        mode: '', //连接方式
        transaction: '', //使用事物
        msgLength: '', //消息最大长度
        sendFileRemove: '', //文件发送后删除
        //http
        decodeType: '', //解码类型
        address: '', //服务地址
        conTimeout: '', //空闲连接超时时间
        backlog: '', //等待连接队列大小
        maxConCount: '', //连接池最大连接数
        //https
        keystore: '', //证书文件
        keypassword: '', //证书密码
        //webService
        dealclass: '', //服务类名

        /** 线程池配置：所有接入设备都需填写该项 **/
        maxSize: '', //最大线程数
        coreSize: '', //核心线程数
        capacity: '', //缓冲队列大小
        aliveTime: '', //空闲线程存活时间

        /** 接包规则配置 **/
        recvRule: '', //接包规则
        maxFrameLength: '', //报文最大长度
        lengthFieldOffset: '', //长度的数据起始位置
        lengthFieldLength: '', //报文数据长度的字段长度
        lengthAdjustment: '', //内容调整长度
        initialBytesToStrip: '', //跳过字节数
        len: '', //定长报文总长度
        endChar: '', //结束符

        /** 配置第三方插件：除去webService设备，其他接出设备都需填写该项 **/
        exterClass: '', //插件类
        externPackAndSend: '', //报文与通讯函数
        externPack: '', //组包函数
        externUnpack: '',//解包函数
        externSend: '',//通讯函数
        beforePack: '', //组包前处理
        beforeSend: '', //发送前请求处理
        beforeUnpack: '', //解包前处理
        beforeReturn: '', //解包后处理

        /** HTTP头配置 **/
        entry: [], //配置键值对
      },


    }
  },

  methods:{
    getSysList(){

    },
    getGroupList(){

    }
  }
}
